/**
 * @class Ext.app.XemPhieuBanHangPanel
 * @extends Ext.panel.Panel
 */
Ext.define('Ext.app.XemPhieuBanHangPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.xemPhieuBanHangPanel',
    id: 'xemPhieuBanHangPanel',
    
    initComponent: function () {
        Ext.apply(this, {
            autoScroll: true,
            border: true,
            layout: 'border',
            titleAlign: 'center',
            items: [
                {
                    region: 'north',
                    xtype: 'form',
                    layout: 'hbox',
                    bodyPadding: 5,
                    bodyStyle: 'background:#ECECEC',
                    items: [{
                        border: false,
                        bodyStyle: 'background:#ECECEC',
                        items: [{
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.TEN"),
                            labelWidth: 50,
                            maxLength: 200,
                            width: 350,
                            margin: '5 5 5 5',
                            anchor: '-5',
                            name: 'customer'
                        }, {
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.DC"),
                            labelWidth: 50,
                            maxLength: 200,
                            width: 350,
                            margin: '5 5 5 5',
                            anchor: '-5',
                            name: 'address'
                        }, {
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.DAT_COC"),
                            labelWidth: 50,
                            maxLength: 200,
                            width: 350,
                            margin: '5 5 5 5',
                            anchor: '-5',
                            name: 'deposit',
                            renderer: function(value) {
                                return formatInteger(value);
                            }
                        }]
                    }, {
                        margin: '0 0 0 5',
                        border: false,
                        bodyStyle: 'background:#ECECEC',
                        items: [{
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.SDT"),
                            labelWidth: 50,
                            maxLength: 25,
                            margin: '5 5 5 5',
                            anchor: '100%',
                            name: 'phone'
                        },{
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.NVBH"),
                            labelWidth: 50,
                            maxLength: 200,
                            width: 350,
                            margin: '5 5 5 5',
                            anchor: '100%',
                            name: 'seller'
                        },{
                            xtype:'displayfield',
                            fieldLabel: translations.get("HOME.DELIVERY_DATE"),
                            labelWidth: 120,
                            maxLength: 200,
                            width: 350,
                            margin: '5 5 5 5',
                            anchor: '100%',
                            name: 'deliveryDate'
                        }]
                    }]
                },
                {
                    region: 'center',
                    xtype: 'gridpanel',
                    columnLines: true,
                    store: {
                        fields: ['stt', 'tenMH', 'dvt', 'chieuDai', 'soTam', 'soLuong', 'donGia', 'thanhTien', 'ghiChu']
                    },
                    columns: [{ 
                        text: translations.get("HOME.STT"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'stt',
                        width: 50
                    },{
                        text: translations.get("HOME.TEN_HANG_HOA"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'tenMH',
                        flex: 1,
                        summaryRenderer: function(value, summaryData, dataIndex) {
                            return "T\u1ed5ng c\u1ed9ng";
                        }
                    },{
                        text: translations.get("HOME.DVT"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'dvt',
                        width: 50
                    },{
                        text: translations.get("HOME.CHIEU_DAI"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'chieuDai',
                        align: 'right',
                        width: 80,
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.SO_TAM"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'soTam',
                        width: 80,
                        align: 'right',
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.SO_LUONG"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'soLuong',
                        align: 'right',
                        width: 80,
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatNumber(value);
                        }
                    },{
                        text: translations.get("HOME.DON_GIA"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'donGia',
                        align: 'right',
                        width: 150,
                        renderer: function(value) {
                            return formatInteger(value);
                        }
                    },{
                        text: translations.get("HOME.THANH_TIEN"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'thanhTien',
                        width: 150,
                        align: 'right',
                        summaryType: 'sum',
                        renderer: function(value) {
                            return formatInteger(value);
                        }
                    },{
                        text: translations.get("HOME.GHI_CHU"),
                        sortable: false,
                        draggable: false,
                        menuDisabled: true,
                        dataIndex: 'ghiChu',
                        width: 150
                    }],
                    tbar: [
                        {
                            text: 'PDF',
                            icon: 'images/pdf.gif',
                            handler: phieuBanHangPDF
                        }
                    ],
                    features: [{
                        ftype: 'summary',
                        dock: 'bottom'
                    }]
                }
            ]            
        });
        this.callParent(arguments);
    },
    
    setRecords: function(obj) {
        this.orderPK = obj.orderPK;
        this.down('[name=customer]').setValue(obj.customer);
        this.down('[name=address]').setValue(obj.address);
        this.down('[name=deposit]').setValue(obj.deposit);
        this.down('[name=phone]').setValue(obj.phone);
        this.down('[name=seller]').setValue(obj.seller);
        this.down('[name=deliveryDate]').setValue(obj.deliveryDate);
        this.down('gridpanel').getStore().add(obj.records);
    }
});
